NAME
find_option - find command line options
SYNTAX
#include <getopt.h>
mixed find_option(string *argv,
- string shortform,
string longform,
string envvar,
mixed def);
DESCRIPTION
This is a generic function to parse command line options of the
type '-f', '--foo' or '--foo=bar'. The first argument should be
the array of strings that is sent as second argument to your
main() function, the second is a string with the short form of
your option. The short form must be only one character long.
The 'longform' is an alternative and maybe more readable way to
give the same option. If you give "foo" as longform your program
will accept --foo as argument. The envvar argument specifies what
environment variable can be used to specify the same option. The
envvar option exists to make it easier to custimizer program usage.
The 'def' has two functions: It specifies that the option takes an
argument and it tells find_option what to return if the option is
not present. If 'def' is given and the option does not have an
argument find_option will print an error message and exit the program.
Also, as an extra bonus: shortform, longform and envvar can all be
arrays, in which case either of the options in the array will be
accpted.
NOTA BENE
find_option modifies argv.
EXAMPLE
int main(int argc, string *argv)
{
- if(find_option(argv,"f","foo"))
- werror("The FOO option was given.\n");
- werror("The BAR option got the "+
find_option(argv,"b","bar","BAR_OPTION","default")+
" argument.\n");
}
SEE ALSO